import java.io.PrintStream;
import java.util.Random;
import java.util.ArrayList;
import utils.*; 
public class SphereSphere {
	private static double max(double x,double y){
		if(x>y) return x; 
		else return y; 
	}
	public static void main(String[] args) throws Exception{
		PrintStream output=new PrintStream("outSPHERE.txt");
		ArrayList<Sphere> allSpheres=new ArrayList<Sphere>(); 
	
		Random gene=new Random();
		double sradius=5; 
		int maxx=0; 
		output.println("#declare spheresphere=union{"); 
		for(int i=0;i<100000;i++){
			double theta=2*Math.PI*gene.nextDouble();
			double phi=2*Math.PI*gene.nextDouble();
			double xz=sradius*Math.cos(theta)*Math.sin(phi);
			double yz=sradius*Math.sin(theta)*Math.sin(phi);
			double zz=sradius*Math.cos(phi); 
			
			
			Sphere sp=new Sphere(xz,yz,zz,1);
			
			double minradius=1;
			double radius=minradius; 
			for(Sphere spc:allSpheres){
				if(sp.intersects(spc)) {
						radius=spc.distance(sp)-spc.getRadius();
						//if(radius<0){System.out.println(radius); System.exit(0); }
						if(radius<minradius)minradius=radius; 
					
				}
				sp.setRadius(minradius); 
			
			}
			
			//if(sp.getRadius()>0.00001)
			if(sp.getRadius()<0.1){maxx++;  }
			allSpheres.add(sp);		
			if(i%1000==0) System.out.println(i);
		}
		for(Sphere sp:allSpheres) {
			output.println(sp);
			//System.out.println(sp); 
		}
		System.out.println(allSpheres.size()); 
		output.println("}");
		System.out.println("done "+maxx); 
		
		
	}
	
	

}
